package com.elantra.serviceImpl;

import com.alibaba.fastjson.JSONObject;
import com.elantra.base.SystemManage;
import com.elantra.dao.ElantraOrganizationMapper;
import com.elantra.dao.ElantraUserMapper;
import com.elantra.entity.ElantraOrganization;
import com.elantra.entity.ElantraUser;
import com.elantra.service.OrganizationService;
import com.elantra.util.Code;
import com.elantra.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class OrganizationImpl implements OrganizationService {


    @Autowired
    private ElantraUserMapper elantraUserMapper;

    @Autowired
    private ElantraOrganizationMapper elantraOrganizationMapper;

    @Override
    public JSONObject listOrg(int page, int rows, String orgName) {

        ElantraUser elantraUser = elantraUserMapper.selectByPrimaryKey(SystemManage.getInstance().getCurrentUserId());
        if (elantraUser==null) {
            return R.To(false,null, Code.C_201);
        }
        PageHelper.startPage(page,rows);
        elantraUser.setMobile(orgName==null?null:orgName.trim());
        List<ElantraOrganization> list = elantraOrganizationMapper.selectAllOrById(elantraUser);
        return R.ToPage(true, list,Code.C_200,new PageInfo(list).getTotal());
    }
}
